<?php
/**
* DataTableColumn.php
*
* Contains DataTableColumn class definition
* @author  John Snook <jsnook@gmail.com>
* @version 2
* @copyright (c) Snook 2004
* @package QuickDataFiles
*/

/**
* DataTableColumn
*
* This class encapsulates the functionality of a cell in a data grid object.  It is a stateful class that will track it's sort orientation as well.
* @author  John Snook <jsnook@gmail.com>
* @version 2
* @copyright (c) Snook 2004
* @example /var/www/corp/IntraDox/Documents.php
* @todo Add ability to handle image drop downs.
* @package QuickData
*/
class DataTableColumn{
	/**#@+
	* @access public
	* @var string
	*/
	var $Caption;
	var $DataMember;
	/**#@-*/
	
	/**#@+
	* @access public
	* @var bool
	*/
	var $Sortable;
	var $Searchable;
	var $Visible = true;
	/**#@-*/
	
	/**
	* @access public
	* @var integer QDT_SORT_NONE, QDT_SORT_ASC or QDT_SORT_DESC
	*/
	var $SortDirection;
	/**
	* @access public
	* @var integer
	*/
	var $Width;
	/**
	* Parent must be a DataTable.
	* @access private
	* @var DataTable
	*/
	var $Parent = NULL;
	var $TemplateRenderFunc = NULL;

	/**#@-*/
	
	var $SortStrings = array(QDT_SORT_NONE => "NONE", QDT_SORT_ASC => "ASC", QDT_SORT_DESC => "DESC");
	
	/**
	* Class Constructor
	* @param string $DataMember Name of bound column
	* @param string $Caption Column header caption
	* @param string $CssClass Name of predefined CSS class
	* @param bool $Sortable Can the column be sorted
	* @param bool $Searchable Can we inclued this column in searching
	* @param string $Url not currently supported
	* @param string $Width column width
	*/
	function DataTableColumn($DataMember, $Caption, $Sortable = FALSE, $Searchable = FALSE, $Width = NULL)
	{
		$this->Caption = $Caption;
		$this->DataMember = $DataMember;
		$this->Sortable = $Sortable;
		$this->Searchable = $Searchable;
		$this->SortDirection = QDT_SORT_NONE;
	}
	
	function GetHeaderHTML()
	{
		$out = '';
		$out .= "\t\t<th id=\"{$this->DataMember}\">";
		if ($this->Sortable) {
			$sort = strtolower($this->SortStrings[$this->SortDirection]);
			$SortDirection = ($this->SortDirection == QDT_SORT_DESC ? 0 : $this->SortDirection + 1);
			$out .= "<a href=\"javascript:{$this->Parent->ObjectName}.ToggleSort('{$this->DataMember}', $SortDirection)\">" . $this->Caption . "</a>&nbsp;<img border=0 src=\"" . $this->Parent->SortIconsURL . $sort . ".gif\" alt=\"$sort\" />";
		} else {
			$out .= $this->Caption;
		}
		$out .= "</th>\n";
		return $out;
	}
}

?>